package org.dromara.crawler.controller;

import cn.hutool.json.JSONObject;
import lombok.RequiredArgsConstructor;
import org.bson.Document;
import org.dromara.common.core.domain.R;
import org.dromara.crawler.domain.TargetEvent;
import org.dromara.crawler.domain.vo.ElementEventVo;
import org.dromara.crawler.mongo.mongodomain.ElementTarget;
import org.dromara.crawler.mongo.mongoservice.ElementEventService;
import org.dromara.crawler.mongo.mongoservice.ElementTargetService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 目标画像模块接口
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/targetImage")
public class TargetImageController {

    private final ElementTargetService elementTargetService;
    private final ElementEventService elementEventService;

    /**
     * 事件目标分组
     */
    @GetMapping("/queryTargetGroup")
    public R<Object> queryTargetGroup(@RequestParam(required = false) String targetInfo) {
        return R.ok(elementTargetService.queryTargetGroup(targetInfo));
    }


    /**
     * 根据targetID获取目标
     */
    @GetMapping("/queryById/{targetId}")
    public R<ElementTarget> queryByTargetId(@PathVariable String targetId) {
        return R.ok(elementTargetService.queryTargetByTargetId(targetId));
    }

    /**
     * 根据targetID获取相关的事件和目标
     */
    @GetMapping("/queryObjectByTargetId/{targetId}")
    public R<JSONObject> queryObjectByTargetId(@PathVariable String targetId) {
        return R.ok(elementEventService.queryObjectByTargetId(targetId));
    }

    /**
     * 根据ID获取目标详细信息
     */
    @GetMapping("/queryDocumentByTargetId/{targetId}")
    public R<JSONObject> queryDocumentByTargetId(@PathVariable String targetId) {
        JSONObject jsonObject  = new JSONObject();
        jsonObject.set("target_info",elementTargetService.queryTargetDocumentByTargetId(targetId));
        return R.ok(jsonObject);
    }

}
